package com.yyx.lgb.manager.controller;

import com.github.pagehelper.PageInfo;
import com.yyx.lgb.common.log.annotation.Log;
import com.yyx.lgb.manager.service.SysRoleService;
import com.yyx.lgb.model.dto.system.SysRoleDto;
import com.yyx.lgb.model.entity.system.SysRole;
import com.yyx.lgb.model.vo.common.Result;
import com.yyx.lgb.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * ClassName: SysRoleController
 * Package: com.yyx.lgb.manager.controller
 * Description:
 *
 * @Author: yyx
 * @Create: 2025/8/1 - 10:41
 */
@RestController
@RequestMapping(value = "/admin/system/sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysRole>> findByPage(@RequestBody SysRoleDto sysRoleDto,
                                                @PathVariable(value = "pageNum") Integer pageNum,
                                                @PathVariable(value = "pageSize") Integer pageSize){
       PageInfo<SysRole> pageInfo= sysRoleService.findByPage(sysRoleDto,pageNum,pageSize);
       return Result.build(pageInfo, ResultCodeEnum.SUCCESS);

    }
    @Log(title = "角色添加",businessType = 0) //添加Log注解，设置属性
    @PostMapping(value = "/saveSysRole")
    public Result saveSysRole(@RequestBody SysRole SysRole) {
        sysRoleService.saveSysRole(SysRole) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
    @PutMapping(value = "/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole SysRole) {
        sysRoleService.updateSysRole(SysRole) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @DeleteMapping(value = "/deleteById/{roleId}")
    public Result deleteById(@PathVariable(value = "roleId") Long roleId) {
        sysRoleService.deleteById(roleId) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    //查询所有角色
    @GetMapping(value = "/findAllRoles/{userId}")
    public Result<Map<String , Object>> findAllRoles(@PathVariable(value = "userId") Long userId) {
        Map<String, Object> resultMap = sysRoleService.findAllRoles(userId);
        return Result.build(resultMap , ResultCodeEnum.SUCCESS)  ;
    }

}
